package com.dll.pybig.utils;

import org.springframework.stereotype.Component;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @author zjj
 */
@Component
public class PyRunner {
    public static void invokePy(String []para) {
        System.out.println("执行....");
        try {
            Process process=Runtime.getRuntime().exec(para);
            BufferedReader reader=new BufferedReader(new InputStreamReader(process.getInputStream(),"GBK"));
            String line;
            while((line=reader.readLine())!=null) {
                System.out.println(line);
            }
            reader.close();
            int i = process.waitFor();//结束子进程
            if(i!=0){
                throw new InterruptedException("执行失败,错误码  "+i);
            }
        } catch (IOException | InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("结束....");
    }
}
